package com.qys.livesMall.system.controller.app;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qys.livesMall.common.result.R;
import com.qys.livesMall.system.modal.dto.QueryBankDTO;
import com.qys.livesMall.system.modal.dto.QueryWalletDTO;
import com.qys.livesMall.system.modal.entity.Bank;
import com.qys.livesMall.system.modal.entity.Wallet;
import com.qys.livesMall.system.modal.vo.BankVO;
import com.qys.livesMall.system.modal.vo.WalletVO;
import com.qys.livesMall.system.service.BankService;
import com.qys.livesMall.system.service.WalletService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;

/**
 * 银行表(Bank)表控制层
 *
 * @author makejava
 * @since 2023-07-07 13:50:10
 */
@RestController
@RequestMapping("/app/wallet")
@RequiredArgsConstructor
@Tag(name = "app-钱包管理", description = "app-钱包管理")
public class AppWalletController {

    private final WalletService walletService;

    /**
     * 分页查询所有数据
     *
     * @return 所有数据
     */
    @PostMapping("/selectAll")
    @Operation(summary = "分页查询所有数据")
    public R<IPage<WalletVO>> selectAll(@RequestBody QueryWalletDTO dto) {
        LambdaQueryWrapper<Wallet> queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.eq(Wallet::getState,1);
        IPage<WalletVO> page = walletService.page(new Page<>(dto.getPageNum(), dto.getPageSize()), queryWrapper).convert(e -> {
            WalletVO walletVO = new WalletVO();
            BeanUtils.copyProperties(e, walletVO);
            return walletVO;
        });
        return R.ok(page);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/{id}")
    @Operation(summary = "通过主键查询单条数据")
    public R<?> selectOne(@PathVariable Serializable id) {
        Wallet wallet = walletService.getById(id);
        if (null == wallet) {
            R.ok();
        }
        WalletVO walletVO = new WalletVO();
        BeanUtils.copyProperties(wallet, walletVO);
        return R.ok(walletVO);
    }

}

